package com.elitesland.system.entity;

import com.elitesland.core.base.BaseModel;
import com.elitesland.system.annotation.Comment;
import com.elitesland.system.convert.BooleanToIntegerConverter;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Objects;

/**
 * <pre>
 *     系统用户账号表
 * </pre>
 *
 * @author Mir
 * @date 2020-06-15
 */
@Entity
@Table(name = "sys_user")
@org.hibernate.annotations.Table(appliesTo = "sys_user", comment = "系统用户账号表")
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value = "系统用户账号表", description = "系统用户账号表")
@DynamicUpdate
public class SysUserDO extends BaseModel implements Serializable {

    private static final long serialVersionUID = -7840804475330315230L;

    @ApiModelProperty(value = "用户账号名称")
    @Comment("用户账号名称")
    @Column(length = 32, nullable = false, unique = true)
    private String username;

    @ApiModelProperty(value = "用户姓氏")
    @Comment("用户姓氏")
    @Column(length = 16)
    private String lastName;

    @ApiModelProperty(value = "用户名称")
    @Comment("用户名称")
    @Column(length = 16)
    private String firstName;

    @ApiModelProperty(value = "用户手机号码")
    @Comment("用户手机号码")
    @Column(length = 16)
    private String mobile;

    @ApiModelProperty(value = "用户邮箱地址")
    @Comment("用户邮箱地址")
    @Column(length = 32)
    private String email;

    @ApiModelProperty(value = "用户账号密码-hashed")
    @Comment("用户账号密码-hashed")
    @Column(length = 128, nullable = false)
    private String password;

    /**
     * <Strong>Mir 2020-09-15 增加账号信息来源字段，默认sys，由系统创建</Strong>
     */
    @ApiModelProperty("账号来源, sys： 系统创建；wec：微信创建；oth：其他方式")
    @Comment("账号来源, sys： 系统创建；wec：微信创建；oth：其他方式")
    @Column(length = 32)
    String sourceType;

    @ApiModelProperty(value = "是否启用")
    @Comment("是否启用")
    @Column()
    @Convert(converter = BooleanToIntegerConverter.class)
    private Boolean enabled;

    @ApiModelProperty(value = "是否同步 0 未同步 1 已同步")
    @Column(name = "trans_flag", columnDefinition = "integer(1) default '0' comment '是否同步 0 未同步 1 已同步'")
    Integer transFlag;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof SysUserDO)) {
            return false;
        }
        if (!super.equals(o)) {
            return false;
        }
        SysUserDO entity = (SysUserDO) o;
        return getId().equals(entity.getId());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getId());
    }
}